<%--                                                                       --%>
<%-- Copyright (c) 2001-2004 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries.                       --%>
<%--                                                                       --%>

<%@ page language="java" %>
<%@ page import = "java.util.*" %>
<%@ page import = "org.apache.struts.util.RequestUtils" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %> 

<bean:define id="micrositeNaviInfoParams" name="micrositeNaviInfoView" property="urlParams" scope="request" />

<script language="javascript" src="<%= request.getContextPath() %>/cs/js/date.js" type="text/javascript">
</script>
<script language="javascript" src="<%= request.getContextPath() %>/cs/js/stringFunc.js" type="text/javascript">
</script>

<script language="javascript">
function openwin(file) {
  window.open(file, "NewWindow", 'toolbar=no, location=no, directories=no, status=no menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes, width=450, height=338');
}

function clickMark(theForm, url) {
  theForm.action = url;
  theForm.submit();
}


<% 
  String nextAction = "/cs/checklistTaskAttachmentAdd.do";
  String nextPage = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           nextAction,
                                           null,
                                           null,
                                           false);
  String relativeDir = "/";// + csTaskEditForm.getServiceName() 
                           //+ "/microsite/" 
                           //+ csTaskEditForm.getMicrositeId(); 

%>



function onClickSave(theForm) {
  if (validateForm(theForm)) {
    theForm.action = '<html:rewrite page="/cs/checklistTaskSave.do"/>';
    theForm.method = "post";
    theForm.submit();
  }
}


function onChangeTaskStatus(theForm) {
  var statusIndex = theForm.taskStatus.selectedIndex;
  var status = theForm.taskStatus.options[statusIndex].value;
  theForm.action = '<html:rewrite page="/cs/checklistTaskChangeStatus.do"/>';
  theForm.method = "post";  
  theForm.submit();
}

function onClickDeleteTask(theForm, url) {
   if (confirm('<bean:message key="cs.checklist.confirmDeleteTask"/>')) {
     theForm.action=url;
     theForm.submit();
     return true;
   }
   else {
     return false;
   }
}


//
// Validate the user's entries.
//
function validateForm(theForm)
{
   var taskName = stringTrim(theForm.name.value);

   if (taskName == "")
   {
      alert("<bean:message key="cs.error.task.name"/>");
      return false;
   }

   var taskDesc = stringTrim(theForm.description.value);
   if (taskDesc.length > 2000) 
   {
      alert("<bean:message key="cs.error.task.description"/>");
      return false;
   }
   var groupIndex = theForm.groupIds.selectedIndex;

   if (groupIndex == -1)
   {
      alert("<bean:message key="cs.error.task.read.group"/>");
      return false;	
   }

   var selectedOwner = document.csTaskEditForm.ownerId.value;

   if (selectedOwner == -1 || selectedOwner == 0)
   {
      alert("<bean:message key="cs.error.task.owner"/>");
      return false;	
   }
   var startDate = getDate2("csTaskEditForm", "start")

   if (startDate == null)
   {
      alert("<bean:message key="cs.error.task.startDate"/>");
      return false;
   }
   var dueDate = getDate2("csTaskEditForm", "due");

   if (dueDate == null)
   {
      alert("<bean:message key="cs.error.task.endDate"/>");
      return false;
   }

   if (startDate.getTime() > dueDate.getTime())
   {
      alert("<bean:message key="cs.error.task.endDateBeforeStartDate"/>");
      return false;
   }

<logic:equal name="csTaskEditForm" property="completed" value="true">
   var completeDate = getDate2("csTaskEditForm", "complete");

   if (completeDate == null)
   {
      alert("<bean:message key="cs.error.task.completeDate"/>");
      return false;
   }

   if (startDate.getTime() > completeDate.getTime())
   {
      alert("<bean:message key="cs.error.task.completeDateBeforeStartDate"/>");
      return false;
   }
   
</logic:equal>

   var attachName = stringTrim(theForm.attName.value);
   var attachFile = stringTrim(theForm.attOriginalFileName.value);

   if (attachName != "" || attachFile != "")
   {
      alert('<bean:message key="cs.error.attachment.add.more"/>');
      return false;
   }

    return true;
}


function 
arrayContainsItem(array, item)
{
   var len_array = array.length;
   var i_array;

   for (i_array = 0; i_array < len_array; i_array++)
   {
      if (array[i_array] == item)
      {
         return true;
      }
   }

   return false;
}


//
// Create a dummy (timestamp) attribute to get around an IE cache problem.
//
function getTimeStamp() {
   var now = new Date;
   var timestamp = '' + now.getYear() + now.getMonth() + now.getDate() + now.getHours() + now.getMinutes() + now.getSeconds() + now.getMilliseconds();
   return timestamp;
}   


function selectOwnerPopup(theForm) {
  var groupIndex = document.csTaskEditForm.groupIds.selectedIndex;

  if (groupIndex == -1) {
    alert("<bean:message key="cs.error.task.read.group"/>");
    return false;	
  }   

  var popupURL = '<html:rewrite page="/cs/contentSelectOwner.do" name="micrositeNaviInfoParams" />';
  var timestamp = getTimeStamp();
  popupURL += '&timestamp=' + timestamp;

  var win = window.open('', "ContentSelectOwner", "width=500,height=400,scrollbars=yes,resizable=yes");
  if ( win != null) {
    if( win.opener == null) {
      win.opener = self;
    }
  }
  win.focus();
  // save the current form setting so that it can be restored later
  var oldAction = theForm.action;
  var oldTarget = theForm.target;
  // submit the form to the popup so that we can pass the groupIds to the popup
  theForm.action = popupURL;
  theForm.target = "ContentSelectOwner";   
  theForm.submit();
  theForm.action = oldAction;
  theForm.target = oldTarget;
}

function setOwner(selectedOwnerId, selectedOwnerName) {
  document.csTaskEditForm.ownerId.value = selectedOwnerId;
  document.csTaskEditForm.ownerName.value = selectedOwnerName;

}

function resetOwner(selectedOwnerId, selectedOwnerName) {
  document.csTaskEditForm.ownerId.value = -1;
  document.csTaskEditForm.ownerName.value = "";

}

</script>


<!-- Zone 5 starts here.  -->

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" 
       summary="content area">
  <tr>
    <td valign="top">
    
    <!--start microsite logo and name here-->
      <div class="pageTitle">
        <%@ include file="/cs/microsite/micrositeNaviInfo.jsp" %>
      </div> 
    <!--end microsite logo and name here-->
    
    <!--  BEGIN form { task } ----------------------------- -->

    <html:form action="/cs/taskSave.do" method="post" >
    <bvhtml:hiddenList name="micrositeNaviInfoView" property="urlParams" scope="request"/>
    <input type="hidden" name="sequenceKey" value=<bean:write name="csTaskEditForm" property="sequenceKey" /> >
    <input type="hidden" name="parentContentType" value="331">
       
  <html:hidden name="csTaskEditForm" property="taskId"/>
  <html:hidden name ="csTaskEditForm" property="completed"/>  
 
  <!--start title bar here-->
  <div class="pageSubtitle">
    <span class="left">
      <logic:equal name="csTaskEditForm" property="taskId" value="0">
         <bean:message key="cs.checklist.task.new"/>
      </logic:equal>
      <logic:notEqual name="csTaskEditForm" property="taskId" value="0">         
          <bean:define id="taskViewName" name="taskEditView" property="persistentName"/>      
	 	  <%String taskName = taskViewName.toString();%>
          <bean:message key="cs.edit" arg0="<%=taskName %>"/> 
      </logic:notEqual>
    </span>
    
    <span class="right">
	&nbsp;
    </span>
  </div>  
  <!--end title bar here-->
  
  <div class="blockWrap">
  
  <!-- start Page Instructions -->
    <div class="pageInstructions">
        <logic:equal name="csTaskEditForm" property="taskId" value="0">
          <bean:message key="cs.tasks.new.note"/>
        </logic:equal>
        <logic:notEqual name="csTaskEditForm" property="taskId" value="0">
          <bean:message key="cs.tasks.edit.note"/>
        </logic:notEqual>
    </div>
    <!-- End Page Instructions -->

  <bean:define id="allPhasesList" name="taskEditView" property="allPhasesList" />
  <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary='<bean:message key="cs.tasks.new"/>'>
    <tr> 
      <td valign="top" nowrap width="16%" class="label"><bean:message key="cs.name"/>*:<b><br>
      </b></td>
      <td valign="top" width="84%" class="labelField" nowrap>
        <html:text property="name" size="31" maxlength="80" />
     </td>
    </tr>
    <tr> 
     <td valign="top" nowrap width="16%" class="label"> 
       <bean:message key="cs.description"/>: 
     </td>
     <td valign="top" width="84%" class="labelField">
       <html:textarea property="description" cols="45" rows="4"/>
    </tr>
    <logic:equal name="micrositeNaviInfoView" property="micrositeTemplatePhaseFlag" value="true">
      <tr> 
        <td valign="top" nowrap width="16%" class="label"><bean:message key="cs.phase"/>*:</td>
        <td valign="top" width="84%" class="labelField"> 
         <bean:write name="taskEditView" property="phaseName"/>
        </td>
      </tr>
    </logic:equal>
    <logic:equal name="micrositeNaviInfoView" property="micrositeTemplatePhaseFlag" value="false">
      <html:hidden property="newPhaseId"/>
    </logic:equal>
    
    <tr> 
      <td valign="top" width="16%" class="label">
        <bean:message key="cs.read.access.groups"/>*:<br>
      </td>
      <td valign="top" width="84%" class="labelField"> 
        <bean:define id="availableGroups" name="taskEditView" property="availableGroups" />
        <html:select property="groupIds" size="4" multiple="true" onchange="resetOwner(this.form)">
          <html:optionsCollection  name="taskEditView" property="availableGroups"/>
        </html:select>
      </td>
    </tr>
    <tr> 
      <td valign="top" nowrap width="16%" class="label"><bean:message key="cs.owner"/>*:</td>
      <td valign="top" width="84%"class="labelField"> 
        <html:text name="csTaskEditForm" property="ownerName" readonly="true"/>
        <input type="hidden" name="ownerId" value=<bean:write name="csTaskEditForm" property="ownerId"/> >
        <html:button property="selectOwner" onclick="selectOwnerPopup(this.form)" styleClass="inputButton">
          <bean:message key="cs.button.select.owner"/>
        </html:button>
      </td>
    </tr>
    
    <tr> 
      <td valign="top" nowrap width="16%" class="label"><bean:message key="cs.priority"/>*:</td>
      <td valign="top" width="84%" class="labelField"> 
        <html:select name="csTaskEditForm" property="priority" size="1">
          <html:option value="0"><bean:message key="cs.high"/></html:option>
          <html:option value="1"><bean:message key="cs.medium"/></html:option>
          <html:option value="2"><bean:message key="cs.low"/></html:option>
        </html:select>
      </td>
    </tr>
    
    <tr> 
      <td valign="top" nowrap width="16%" class="label"><bean:message key="cs.tasks.startDate"/>:</td>
      <td valign="top" width="84%" class="labelField">  
        <bvhtml:date name="csTaskEditForm" property="start"/>
        <a href="JavaScript:datePopup('<html:rewrite page="/cs/calendar.do"/>', 'csTaskEditForm','start')"><img src="<%= request.getContextPath() %>/cs/images/icons/calendar.gif" border="0" align="absmiddle"/></a>
      <bvhtml:time name="csTaskEditForm" property="start"/>
      </td>
    </tr> 
    <tr> 
      <td valign="top" nowrap width="16%" class="label"><bean:message key="cs.tasks.dueDate"/>:</td>
      <td valign="top" width="84%" class="labelField">  
        <bvhtml:date name="csTaskEditForm" property="due"/>
        <a href="JavaScript:datePopup('<html:rewrite page="/cs/calendar.do"/>', 'csTaskEditForm','due')"><img src="<%= request.getContextPath() %>/cs/images/icons/calendar.gif" border="0" align="absmiddle"/></a>
        <bvhtml:time name="csTaskEditForm" property="due"/>
      </td>
    </tr>
    
    <logic:equal name="taskEditView" property="completed" value="true">
    <tr> 
       <td valign="top" nowrap width="16%" class="label"><bean:message key="cs.tasks.completionDate"/>:</td>
       <td valign="top" width="84%" class="labelField">  
         <input type="hidden" name="completed" value="true">
         <bvhtml:date name="csTaskEditForm" property="complete"/>
         <a href="JavaScript:datePopup('<html:rewrite page="/cs/calendar.do"/>', 'csTaskEditForm','complete')"><img src="<%= request.getContextPath() %>/cs/images/icons/calendar.gif" border="0" align="absmiddle"/></a>
         <bvhtml:time name="csTaskEditForm" property="complete"/>
      </td>
    </tr>
    </logic:equal>
   
   <tr> 
    <td valign="top" nowrap width="16%" class="label"><bean:message key="cs.status"/>*:</td>
    <td valign="top" width="84%" class="labelField"> 
      <html:select name="csTaskEditForm" property="taskStatus" size="1" onchange="return onChangeTaskStatus(this.form);">
        <html:option value="3"><bean:message key="cs.status.active"/></html:option>
        <html:option value="1"><bean:message key="cs.status.pending"/></html:option>
        <html:option value="2"><bean:message key="cs.status.completed"/></html:option>
        <html:option value="4"><bean:message key="cs.status.deferred"/></html:option>
      </html:select>
    </td>   
   </tr>
	
  </table>
  
<script language="JavaScript">
   var nextPage = '<html:rewrite page="/cs/checklistTaskAttachmentAdd.do"/>';
   var attachmentDeleteAction = '<html:rewrite page="/cs/checklistTaskAttachmentDelete.do" />';

  <logic:equal name="csTaskEditForm" property="taskId" value="0">
    var nextActionAfterCancel = '/cs/checklistTaskList.do';
    var nextActionAfterReset = '/cs/checklistTaskNew.do';
  </logic:equal>
  <logic:notEqual name="csTaskEditForm" property="taskId" value="0">
    var nextActionAfterCancel = '/cs/checklistTaskView.do';
    var nextActionAfterReset = '/cs/checklistTaskEdit.do';
  </logic:notEqual>
</script>
    
<bean:define id="formBeanUsed" name="csTaskEditForm" toScope="request" />
<%@ include file="/cs/microsite/attachment/attachmentEdit.jsp" %>
 
	<!-- End of Related Items section    -->

<!--start cancel, reset, save bar area here-->

    <div class="pageButtonWrap" align="right">
      <input type="button" class="pageButton" name="newBtn"
                 value='<bean:message key="button.reset"/>'
                 titleKey="button.new"
                 onclick="return resetAttachment(this.form)">
	&nbsp;&nbsp;
      <input type="button" class="pageButton" name="cancelBtn"
             value='<bean:message key="button.cancel"/>'
             titleKey="button.cancel"
             onclick="return cancelClearAttachment(this.form)">
             
      <input type="button"  class="pageButton" name="saveBtn"
             titleKey="button.save" onclick="onClickSave(this.form)"
             value='<bean:message key="button.save"/>'>
             
    </div>          
    <!--end cancel, reset, save bar area here-->
    </html:form>
    </div>

    </td>
  </tr>
</table>


<!--end zone 5 content here -->



